package com.estronger.shopmanage.adapter;

import java.util.List;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.estronger.shopmanage.base.BaseHolder;

//	implements OnItemClickListener 
public abstract class DefaultAdapter<Data> extends BaseAdapter {

	protected List<Data> datas;

	public List<Data> getDatas() {
		return datas;
	}

	public void setDatas(List<Data> datas) {
		this.datas = datas;
	}

	public DefaultAdapter(List<Data> datas) { // ,ListView lv
		this.datas = datas;
	}

	@Override
	public int getCount() {
		return datas.size();
	}

	@Override
	public Object getItem(int position) {
		return datas.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		BaseHolder holder = null;

		if (convertView == null) {
			holder = getHolder();
		} else {
			holder = (BaseHolder) convertView.getTag();
		}
		if (position < datas.size()) {
			holder.setData(datas.get(position));
		}
		return holder.getContentView();
	}

	protected abstract BaseHolder<Data> getHolder();

}
